package q165_compareVersion;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Solution_1 {
    public static void main(String[] args) {
        String a = "1.001.1";
        String[] b = a.split("\\.");
        List<Integer> collect = Arrays.stream(b).map(Integer::parseInt).collect(Collectors.toList());

        System.out.println(collect);
    }
    public int compareVersion(String version1, String version2) {
        int ans = 0;
        // 拆分字符串
        String[] v1 = version1.split("\\.");
        String[] v2 = version2.split("\\.");
        // 用流的方式可以直接将字符串数组转换为整型list
        // List<Integer> collect = Arrays.stream(v1).map(Integer::parseInt).collect(Collectors.toList());
        int index = 0;
        while (index < Math.max(v1.length, v2.length)) {
            int l1 = index < v1.length ? Integer.parseInt(v1[index]) : 0;
            int l2 = index < v2.length ? Integer.parseInt(v2[index]) : 0;
            if (l1 == l2) {
                index++;
            }else {
                return l1 > l2 ? 1 : -1;
            }
        }

        return ans;
    }
}
